package edu.nanyang.controller;

import edu.nanyang.domain.StudentInfo;
import edu.nanyang.service.StudentInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class StudentLoginController extends BaseController{
    @Resource
    private StudentInfoService studentInfoService;
    @PostMapping("/studentlogin")
    public String studentLogin(int studentNum,String studentPassword){
        StudentInfo studentInfo= studentInfoService.getByStudentNumAndPassword(studentNum,studentPassword);
        if(studentInfo!=null){
            HttpSession session=request.getSession();
            session.setAttribute("login_student",studentInfo);
            return "index";
        }else{
            request.setAttribute("tip_info","用户名和密码错误");
            return "student_login";
        }
    }

    @GetMapping("studentlogout")
    public String studentLogout(){
        //session失效
        request.getSession().invalidate();
        return "student_login";
    }
}
